#INCLUDE "Protheus.Ch"


/*
ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ
Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±
Â±Â±ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÂ»Â±Â±
Â±Â±ÂºPrograma  Â³FSWUSZ0   ÂºAutor  Â³ Fabricio Zanette   Âº Data Â³  19/10/11   ÂºÂ±Â±
Â±Â±ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÂ¹Â±Â±
Â±Â±ÂºDesc.     Â³ compatibilizador para criar campos indices e tabelas     , ÂºÂ±Â±
Â±Â±Âº          Â³ relativo a tabela SZ0.                                     ÂºÂ±Â±
Â±Â±ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÂ¼Â±Â±
Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±Â±
ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ
*/
                                                              
*********************
User Function ComZa0(aRecnoSm0)
*********************      
*********************

Local lMark 		:= .F.
Local oOk		:= LoadBitmap( GetResources(), "CHECKED" )   //CHECKED    //LBOK  //LBTIK
Local oNo		:= LoadBitmap( GetResources(), "UNCHECKED" ) //UNCHECKED  //LBNO
Local cTexto    
Local cAux 		:= ""


Local aSx2 := {}    // Array para enviar os parametros da funÃ§Ã£o CriaSx2
Local aSx3 := {}   // Array para enviar os parametros da funÃ§Ã£o CriaSx3
Local aSix := {}   // Array para enviar os parametros da funÃ§Ã£o CriaSix
Local aSx5 := {}
Local aSx6 := {}   // Array para enviar os parametros da funÃ§Ã£o CriaSX6
Local aSx7 := {}   // Array para enviar os parametros da funÃ§Ã£o CriaSX6
Local aSxA := {}   // Array para enviar os parametros da funÃ§Ã£o CriaSXA
Local aSxB := {}   // Array para enviar os parametros da funÃ§Ã£o CriaSXB 



Local cMask:= ""


//--------------------------------------------------------------------------------------------------------------------------------------
/// COLOCAR OS DADOS PARA CRIAÃÃO   --- INICIO ---                                                                                      


 //Adicionar os dados da tabela
AADD( aSX2 , {  'ZA0','                                        ','ZA0010  ','RESTRICAO COND.PAG X VENDEDOR ','RESTRICAO COND.PAG X VENDEDOR ','RESTRICAO COND.PAG X VENDEDOR ','                                        ','C','C','C',0,' ','                                                                                                                                                                                                                                                          ',' ',0,'                                                                                                                                                                                                                                                              '               } ) 
  
 

 // adicionar os dados dos campos
	
 AADD( aSx3 , {  'ZA0','','ZA0_FILIAL','C',2,0,'Filial      ','Sucursal    ','Branch      ','Filial do Sistema        ','Sucursal                 ','Branch of the System     ','@!                                           ','                                                                                                                                ','€€€€€€€€€€€€€€€','                                                                                                                                ','      ',1,'þA',' ',' ','U','N',' ',' ',' ','                                                                                                                                ','                                                                                                                                ','                                                                                                                                ','                                                                                                                                ','                    ','                                                            ','                                                                                ','033',' ',' ','                                                                                                                                                                                                                                                          ','                                                                                                                                                                                                                                                          ',' ',' ',' ','               '               } ) 
 AADD( aSx3 , {  'ZA0','','ZA0_CONDPA','C',3,0,'Cond. Pagam ','Cond. Pagam ','Cond. Pagam ','Condicao de pagamento    ','Condicao de pagamento    ','Condicao de pagamento    ','                                             ','                                                                                                                                ','€€€€€€€€€€€€€€ ','                                                                                                                                ','SE4   ',0,'þA',' ',' ','U','S','A','R','€','VAZIO() .OR. EXISTCPO("SE4")                                                                                                    ','                                                                                                                                ','                                                                                                                                ','                                                                                                                                ','                    ','                                                            ','                                                                                ','   ',' ',' ','                                                                                                                                                                                                                                                          ','                                                                                                                                                                                                                                                          ',' ','N','N','               '               } ) 
 AADD( aSx3 , {  'ZA0','','ZA0_GRUPO ','C',6,0,'Grupo       ','Grupo       ','Grupo       ','Grupo do vendedor        ','Grupo do vendedor        ','Grupo do vendedor        ','                                             ','                                                                                                                                ','€€€€€€€€€€€€€€ ','                                                                                                                                ','      ',0,'þA',' ',' ','U','S','A','R',' ','                                                                                                                                ','                                                                                                                                ','                                                                                                                                ','                                                                                                                                ','                    ','                                                            ','                                                                                ','   ',' ',' ','                                                                                                                                                                                                                                                          ','                                                                                                                                                                                                                                                          ',' ','N','N','               '               } ) 
 AADD( aSx3 , {  'ZA0','','ZA0_VEND  ','C',6,0,'Vendedor    ','Vendedor    ','Vendedor    ','Vendedor                 ','Vendedor                 ','Vendedor                 ','                                             ','                                                                                                                                ','€€€€€€€€€€€€€€ ','                                                                                                                                ','SA3   ',0,'þA',' ',' ','U','S','A','R',' ','VAZIO() .OR. ExistCpo("SA3")                                                                                                    ','                                                                                                                                ','                                                                                                                                ','                                                                                                                                ','                    ','                                                            ','                                                                                ','   ',' ',' ','                                                                                                                                                                                                                                                          ','                                                                                                                                                                                                                                                          ',' ','N','N','               '               } ) 




// Adicionar os dados dos indices

 AADD( aSix , {  'ZA0','','ZA0_FILIAL+ZA0_CONDPA+ZA0_GRUPO+ZA0_VEND                                                                                                                        ','Cond. Pagam+Grupo+Vendedor                                            ','Cond. Pagam+Grupo+Vendedor                                            ','Cond. Pagam+Grupo+Vendedor                                            ','U','                                                                                                                                                                ','          ','N'               } ) 
 AADD( aSix , {  'ZA0','','ZA0_FILIAL+ZA0_CONDPA+ZA0_VEND                                                                                                                                  ','Cond. Pagam+Vendedor                                                  ','Cond. Pagam+Vendedor                                                  ','Cond. Pagam+Vendedor                                                  ','U','                                                                                                                                                                ','          ','N'               } ) 



/// COLOCAR OS DADOS PARA CRIAÃÃO   --- FIM ---
//_----------------------------------------------------------------------------------------------------------------------------------------------

cLog += + chr(13) + chr(10)+ "*** Atualizando Tabela: " + aSX2[1][1]    

For a:=1 To Len(aRecnoSm0)
	
	// se a empresa nao foi selecionada apenas da um next;
	If aRecnoSm0[a][1] == .F.
		Loop
	EndIf
	
	cLog += "**** Atualizando dados da Empresa: "+aRecnoSm0[a][2]+ " " + aRecnoSm0[a][3] + " Filial: "+aRecnoSm0[a][4] +" ****" + chr(13) + chr(10)
  
	
	//altera empresa e filial para a selecionada
	RpcClearEnv()
	RpcSetType(2)
	RpcSetEnv(aRecnoSm0[a][2], aRecnoSm0[a][4])
	                                               
	
	

	//FunÃ§Ã£o para criar Tabelas no Sistema.
	 Processa({||	U_CriaSx2(aSx2) ,"Atualizando SX2 "})
		 
	
	 //FunÃ§Ã£o para criar Campos no Sistema.
	 Processa({||	U_CriaSx3(aSx3) ,"Atualizando SX3 "})
	
     //FunÃ§Ã£o para criar os Indices no sistema.
     Processa({||	U_CriaSix(aSix) ,"Atualizando SiX "})
	
	
	
Next a

//Adiciona no log
U_appendToLog(cLog)

Return()


